﻿using System;
using System.Data;
using System.Collections.Generic;
using ZHDJ.MobileInterface.Common;

namespace ZHDJ.MobileInterface
{
    public partial class GetLawCaseAnalysis : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            LawCaseAnalysisOutParam result = new LawCaseAnalysisOutParam();
            LawCaseAnalysisInParam param = new LawCaseAnalysisInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as LawCaseAnalysisInParam;


                if (param.page_no * param.page_count <= 0)
                {
                    result.code = "0";
                    result.desc = "当前页,以及页记录条数必须为大于0的正整数";

                    isFlag = false;
                }

                if (isFlag)
                {
                    DataSet ds = SXT.Party.Law.BLL.CommonUtils.GetCaseAnalysisList(param.CaseType, param.Keywords, param.page_no, param.page_count, "MobileService");
                    if (ds != null && ds.Tables.Count == 2)
                    {
                        LawCaseAnalysisData itemTemp;
                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[1].Rows[0][0]), param.page_count);
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            itemTemp=new LawCaseAnalysisData();
                            itemTemp.CaseID = dr["CaseID"].ToString();
                            itemTemp.CaseTitle = dr["CaseTitle"].ToString();
                            itemTemp.Content = dr["Content"].ToString().Replace("src=\"/fs/UploadFiles/party", "src=\"http://www.ith71.cn/fs/UploadFiles/party");
                            itemTemp.LawContent = dr["LawEx"].ToString().Replace("src=\"/fs/UploadFiles/party", "src=\"http://www.ith71.cn/fs/UploadFiles/party");
                            itemTemp.AnalysisContent = dr["AnalysisEx"].ToString().Replace("src=\"/fs/UploadFiles/party", "src=\"http://www.ith71.cn/fs/UploadFiles/party");
                            itemTemp.CreateTime=dr["CreateTime"].ToString();
                            itemTemp.CaseNO = dr["CaseNO"].ToString();

                            result.data.list.Add(itemTemp);
                        }
                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetLawCaseAnalysis", SerializeHelper.JsonSerializer<LawCaseAnalysisInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<LawCaseAnalysisInParam, LawCaseAnalysisOutParam>();
            else
                SafeProcessRequest<LawCaseAnalysisInParam, LawCaseAnalysisOutParam>();
        }
    }

    #region 请求参数
    public class LawCaseAnalysisInParam
    {
        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }

        /// <summary>
        /// 类型  0：劳资纠纷  1：刑事纠纷
        /// </summary>
        public string CaseType
        { get; set; }

        /// <summary>
        /// 关键字
        /// </summary>
        public string Keywords
        { get; set; }
    }
    #endregion


    #region 结果参数
    public class LawCaseAnalysisOutParam
    {
        public LawCaseAnalysisOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new LawCaseAnalysisList();
        }

        public string code
        { get; set; }

        public string desc
        { get; set; }

        public LawCaseAnalysisList data
        { get; set; }

    }

    public class LawCaseAnalysisList
    {
        public LawCaseAnalysisList()
        {
            total_pages = 0;
            list = new List<LawCaseAnalysisData>();
        }

        public List<LawCaseAnalysisData> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }

    public class LawCaseAnalysisData
    {
        /// <summary>
        /// ID
        /// </summary>
        public string CaseID
        { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string CaseTitle
        { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        public string Content
        { get; set; }

        /// <summary>
        /// 法律条文
        /// </summary>
        public string LawContent
        { get; set; }

        /// <summary>
        /// 案例解析
        /// </summary>
        public string AnalysisContent
        { get; set; }

        public string CreateTime
        { get; set; }

        public string CaseNO
        { get; set; }
    }
    #endregion
}